package erupt_simultaneously;

import java.util.concurrent.TimeUnit;

/**
 * @Auther Jun jie Yi
 * @Date 16:38 2021/7/29
 */
public class VolatileDemo {

    //volatile 保证线程的可见性
    volatile static boolean running =true;
    void m(){
        System.out.println("m start");
        while(running){

        }
        System.out.println("m end");
    }

    public static void main(String[] args) {
        VolatileDemo v=new VolatileDemo();
        new Thread(v::m,"t1").start();
        try{
            TimeUnit.SECONDS.sleep(1);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        v.running=false;
    }
}
